package kr.hkit.androidcomplete02.ch03;

import kr.hkit.androidcomplete02.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;

public class DatePickerTest extends Activity {
	DatePicker mDate;
	TextView mTxtDate;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.date_picker_test);

		mDate = (DatePicker) findViewById(R.id.datepicker);
		mTxtDate = (TextView) findViewById(R.id.txtdate);

		mDate.init(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(),
				new DatePicker.OnDateChangedListener() {

					@Override
					public void onDateChanged(DatePicker view, int year,
							int monthOfYear, int dayOfMonth) {
						mTxtDate.setText(String.format("%d/ %d/ %d", year,
								monthOfYear + 1, dayOfMonth));

						findViewById(R.id.btnnow).setOnClickListener(
								new View.OnClickListener() {

									@Override
									public void onClick(View v) {
										String result = String.format(
												"%d년 %d월 %d 일",
												mDate.getYear(),
												mDate.getMonth() + 1,
												mDate.getDayOfMonth());
										Toast.makeText(DatePickerTest.this,
												result, 0).show();

									}
								});
					}
				});
	}
}
